//
//  SitPositionSetView.m
//  Mahjong
//
//  Created by 饶首建 on 17/7/21.
//  Copyright © 2017年 com.ikamobile.com. All rights reserved.
//

#import "SitPositionSetView.h"
#import "HWPopTool.h"

@interface SitPositionSetView()
@property (weak, nonatomic) IBOutlet UIButton *northBtn;
@property (weak, nonatomic) IBOutlet UIButton *westBtn;
@property (weak, nonatomic) IBOutlet UIButton *eastBtn;
@property (weak, nonatomic) IBOutlet UIButton *southBtn;

@property (nonatomic,assign) SitPositionType type;

@end

@implementation SitPositionSetView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
+ (instancetype)sitPositionSetView{
    return [[[NSBundle mainBundle] loadNibNamed:@"SitPositionSetView"
                                          owner:nil options:nil]lastObject];
}

- (void)setDefault{
    _type = [[NSUserDefaults standardUserDefaults]integerForKey:NSUSERDEFAULTS_KEY_SITPOSITION];
    switch (_type) {
        case SitPositionTypeNorth:
            [_northBtn setImage:UIImageWithName(@"btn_selected") forState:UIControlStateNormal];
            [_northBtn setTitleColor:UIColorHex(6AB6EE) forState:UIControlStateNormal];
            break;
        case SitPositionTypeWest:
            [_westBtn setImage:UIImageWithName(@"btn_selected") forState:UIControlStateNormal];
            [_westBtn setTitleColor:UIColorHex(6AB6EE) forState:UIControlStateNormal];
            break;
        case SitPositionTypeSouth:
            [_southBtn setImage:UIImageWithName(@"btn_selected") forState:UIControlStateNormal];
            [_southBtn setTitleColor:UIColorHex(6AB6EE) forState:UIControlStateNormal];
            break;
        case SitPositionTypeEast:
            [_eastBtn setImage:UIImageWithName(@"btn_selected") forState:UIControlStateNormal];
            [_eastBtn setTitleColor:UIColorHex(6AB6EE) forState:UIControlStateNormal];
            break;
            
        default:
            break;
    }
}


- (void)setStatus{
    [_northBtn setImage:UIImageWithName(@"btn_default") forState:UIControlStateNormal];
    [_northBtn setTitleColor:UIColorHex(4A4A4A) forState:UIControlStateNormal];
    
    [_westBtn setImage:UIImageWithName(@"btn_default") forState:UIControlStateNormal];
    [_westBtn setTitleColor:UIColorHex(4A4A4A) forState:UIControlStateNormal];
    
    [_eastBtn setImage:UIImageWithName(@"btn_default") forState:UIControlStateNormal];
    [_eastBtn setTitleColor:UIColorHex(4A4A4A) forState:UIControlStateNormal];
    
    [_southBtn setImage:UIImageWithName(@"btn_default") forState:UIControlStateNormal];
    [_southBtn setTitleColor:UIColorHex(4A4A4A) forState:UIControlStateNormal];
}

- (IBAction)northAction:(id)sender {
    [self setStatus];
    _type = SitPositionTypeNorth;
    [_northBtn setImage:UIImageWithName(@"btn_selected") forState:UIControlStateNormal];
    [_northBtn setTitleColor:UIColorHex(6AB6EE) forState:UIControlStateNormal];
}
- (IBAction)westAction:(id)sender {
    [self setStatus];
    _type = SitPositionTypeWest;
    [_westBtn setImage:UIImageWithName(@"btn_selected") forState:UIControlStateNormal];
    [_westBtn setTitleColor:UIColorHex(6AB6EE) forState:UIControlStateNormal];
    
}
- (IBAction)eastAction:(id)sender {
    [self setStatus];
    _type = SitPositionTypeEast;
    [_eastBtn setImage:UIImageWithName(@"btn_selected") forState:UIControlStateNormal];
    [_eastBtn setTitleColor:UIColorHex(6AB6EE) forState:UIControlStateNormal];
}
- (IBAction)southAction:(id)sender {
    [self setStatus];
    _type = SitPositionTypeSouth;
    [_southBtn setImage:UIImageWithName(@"btn_selected") forState:UIControlStateNormal];
    [_southBtn setTitleColor:UIColorHex(6AB6EE) forState:UIControlStateNormal];
}
- (IBAction)sureAction:(id)sender {
    [[NSUserDefaults standardUserDefaults]setObject:@(_type) forKey:NSUSERDEFAULTS_KEY_SITPOSITION];
    [[HWPopTool sharedInstance]closeWithBlcok:^{
        
    }];
}


@end
